/**
 * FileName: WechatIndexController
 * Author:   Leopold
 * Date:     2018/9/4 11:16
 * Description: 微信入口
 * History:
 */
package cn.mcsys.platform.core.web;

import cn.mcsys.myadmin.common.utils.DateUtils;
import cn.mcsys.myadmin.common.web.JsonResult;
import cn.mcsys.myadmin.dubbo.service.BackService;
import cn.mcsys.myadmin.modules.air.entity.AirCarSumRecord;
import cn.mcsys.platform.core.service.PlatformService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class AirShowAreaController {

    private static Logger logger = LoggerFactory.getLogger(AirShowAreaController.class);

    @Autowired
    private BackService backService;

    @Autowired
    private PlatformService platformService;

    @RequestMapping("airShowArea")
    public String airShowArea(Model model) {
        System.out.println("go to airShowArea!getting data");
//        Map<String, Object> result = platformService.getAirShowArea();
//        model.addAttribute("dataMap", result);
        return "airShowArea";
    }

    @GetMapping("getGps")
    @ResponseBody
    public JsonResult getGps() {
        System.out.println("getGps....");
        return JsonResult.success(platformService.getGps());
    }

    @GetMapping("getTaxiTrend")
    @ResponseBody
    public JsonResult getTaxiTrend() {
        Date date1 = DateUtils.parseDate(DateUtils.getDate("yyyy-MM-dd"));
        Date date2 = DateUtils.getDateBeforeDays(date1, 1);
        Date date3 = DateUtils.getDateBeforeDays(date1, 7);
        List<AirCarSumRecord> recordList1 = backService.getSumRecordWithTime(date1);
        List<AirCarSumRecord> recordList2 = backService.getSumRecordWithTime(date2);
        List<AirCarSumRecord> recordList3 = backService.getSumRecordWithTime(date3);
        Map<String,Object> result = new HashMap<>();
        result.put("recordList1",recordList1);
        result.put("recordList2",recordList2);
        result.put("recordList3",recordList3);
        return JsonResult.success(result);
    }

}
